package cn.ekuma.epos.analysis.front.model;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.openbravo.bean.erp.viewbean.PassengerFlowTransaction;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.util.RoundUtils;

public class PassengerFlowTransactionTableModel extends AbstractTableModel{
    
    List<PassengerFlowTransaction> rows;
    
    public PassengerFlowTransactionTableModel() {
        rows=new ArrayList();
    }

    public void resert( List<PassengerFlowTransaction> rows){
        this.rows=rows;
        this.fireTableStructureChanged();
    }

    public int getRowCount() {
        return rows.size();
    }

    @Override
    public String getColumnName(int column) {
        return COLUMNS[column];
    }

    public int getColumnCount() {
        return COLUMNS.length;
    }

    public PassengerFlowTransaction get(int index){
        return rows.get(index);
    }

    public static String[] COLUMNS=new String[]{
           AppLocal.getIntString("label.time"),
           AppLocal.getIntString("label.PassengerFlowTransaction.passengerFlow"),
           AppLocal.getIntString("label.PassengerFlowTransaction.passengerUnit"),
           AppLocal.getIntString("label.pricesellCount"),
           AppLocal.getIntString("label.pricebuyCount"),
           AppLocal.getIntString("label.profits")
    };
    

    public Object getValueAt(int rowIndex, int columnIndex) {
    	PassengerFlowTransaction obj=rows.get(rowIndex);
    	switch(columnIndex){
    	case 0:
    		return Formats.TIMESTAMP.formatValue(obj.getCurDate());
    	case 1:
    		return Formats.CURRENCY.formatValue(obj.getTotalPrice()/obj.getUnit());
    	case 2:
    		return obj.getUnit();
    	case 3:
    		return RoundUtils.round(obj.getTotalPrice());
    	case 4:
    		return RoundUtils.round(obj.getConsultCost());
    	case 5:
    		return RoundUtils.round(obj.getTotalPrice()-obj.getConsultCost());
    	}
        return null;
    }
    
    public Class<?> getColumnClass(int columnIndex) {
		if(columnIndex==3||columnIndex==4||columnIndex==5){
			return Double.class;
		}
		return super.getColumnClass(columnIndex);
	}
}